/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ppsa.dao;


import com.ppsa.bean.AlertaBean;
import com.ppsa.bean.UsuarioBean;
import com.ppsa.common.Constantes;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;

/**
 *
 * @author AdminTdp
 */
public class AlertaDao extends AccesoDao {
    static final Logger m_log = Logger.getLogger(AlertaDao.class.getName());
    public AlertaDao() throws AccesoDaoException {
        super();
    }

    public List<AlertaBean> listarAlerta( AlertaBean objL_alerta , UsuarioBean objL_usuario ) throws Exception {
        m_log.info("[listarAlerta] << ENTER");
        List<AlertaBean> lstL = new ArrayList<AlertaBean>();

        AlertaBean objL = null;
        //TareaBean objL_tarea = null;
        try {
            //this.objPt_conn = objPt_dataSource.getConnection();
            this.objPt_conn = DriverManager.getConnection(strpv_conexionUrl);
            
            String strl_procedure = "{ call "+Constantes.PREFIJO_SP+"listarAlerta(?) }";
            objPt_cstmt = objPt_conn.prepareCall(strl_procedure);
            objPt_cstmt.setString(1, objL_usuario.getStrpv_codigoUsuario());
            objPt_rs = objPt_cstmt.executeQuery();
            while( objPt_rs.next() ) {
                objL = new AlertaBean();
                
                objL.setStrpv_codigoAlerta(objPt_rs.getString("ID_ALERTA"));
                objL.setStrpv_descripcionAlerta(objPt_rs.getString("DESCRIPCION"));
                objL.setStrpv_fechaAlerta(objPt_rs.getString("FECHA"));
           
                lstL.add(objL);
            }
        } catch ( Exception ex ) {
            ex.printStackTrace();
        } finally {
            closeCallableStatement(objPt_cstmt);
            closeResultSet(objPt_rs);
            closeConnection(objPt_conn);
        }
        m_log.info("[listarAlerta] >> EXIT ");
        return lstL;
    }
    public int obtenerCantidadAlerta( AlertaBean objL_alerta, UsuarioBean objL_usuario ) throws Exception {
        m_log.info( "[obtenerCantidadAlerta] << ENTER" );
        Integer intpv_temp = 0;
        //TareaBean objL_tarea = null;
        try {
            //this.objPt_conn = objPt_dataSource.getConnection();
            this.objPt_conn = DriverManager.getConnection( strpv_conexionUrl );
            String strl_procedure = "{ call ppsa_sp_obtenerCantidadAlerta(?,?) }";
            objPt_cstmt = objPt_conn.prepareCall( strl_procedure );
            objPt_cstmt.setString( 1, objL_usuario.getStrpv_codigoUsuario() );
            objPt_cstmt.registerOutParameter( 2, java.sql.Types.INTEGER );
            objPt_cstmt.execute();
            intpv_temp = objPt_cstmt.getInt( 2 );

        } catch ( Exception ex ) {
            ex.printStackTrace();
        } finally {
            closeCallableStatement( objPt_cstmt );
            closeResultSet( objPt_rs );
            closeConnection( objPt_conn );
        }
        m_log.info( "[obtenerCantidadAlerta] >> EXIT " );
        return intpv_temp;
    }
}
